﻿if (typeof(Five) == 'undefined')
    Five = {};

Five.Cart = {
    Add: function (pi) {
        var data = new TIO().ajax("../Service/AddToCart.ashx?pi=" + pi, "");
        if (data.note == "NONEPRODUCT") {
            alert('Product is not exists !');
        }
        if (typeof (data.totalitem) != 'undefined') {
            $("[id$='cart_totalItem']").html(data.totalitem);
            $("[id$='cart_totalPrice']").html(data.totalprice);
            alert("You've have " + data.totalitem + " item(s) in cart");
        }
    },
    Remove: function (pi) {
        var data = new TIO().ajax("../Service/RemoveCart.ashx?pi=" + pi, "");
        if (typeof (data.totalitem) != 'undefined') {
            $("[id$='cart_totalItem']").html(data.totalitem);
            $("[id$='cart_totalPrice']").html(data.totalprice);

            this.ShowDetail();
        }
    },
    ShowDetail: function () {
        var data = new TIO().ajaxGetHandle("../Service/ShowCartDetail.ashx");
        $("#tblCartDetail").html(data);
        Five.Cart.Detail.InitEvent();
    },

    UpdateQuantity: function (pi, quantity) {
        var data = new TIO().ajax("../Service/UpdateCart.ashx?pi=" + pi + "&q=" + quantity, "");
        if (typeof (data.totalitem) != 'undefined') {
            $("[id$='cart_totalItem']").html(data.totalitem);
            $("[id$='cart_totalPrice']").html(data.totalprice);

            this.ShowDetail();
        }
    }
};

$(function() {
    Five.Cart.ShowDetail();
});